﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using FastReflectionLib;
using XYTXL.API;
using Newtonsoft.Json;
using XYTXL.Data;
using System.Data;
using Newtonsoft.Json.Linq;
using System.Net;
using System.Configuration;
using System.IO;
using System.Xml;
using Newtonsoft.Json.Converters;
using System.Drawing;
using System.Drawing.Imaging;
using OMCS.Engine.WhiteBoard;
using ESBasic;
using System.Threading.Tasks;
using Senparc.Weixin.MP.AdvancedAPIs.OAuth;
using Senparc.Weixin.MP.AdvancedAPIs;
using Senparc.Weixin;

namespace XYTXL.API
{
    public class Commanage : IWsService
    {
        public void ProcessRequest(HttpContext context, ref Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            MethodInfo methodInfo = typeof(Commanage).GetMethod(msg.Action.ToUpper());
            Commanage model = new Commanage();
            methodInfo.FastInvoke(model, new object[] { context, msg, P1, P2, UserInfo });
        }


        #region 登录注册
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1">用户名</param>
        /// <param name="P2">密码（未解码的）</param>
        /// <param name="UserInfo"></param>
        public void LOGIN(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string password = context.Request["password"];
            string username = context.Request["UserName"];
            JH_Auth_User userInfo = new JH_Auth_User();

            List<JH_Auth_User> userList = new JH_Auth_UserB().GetEntities(d => (d.UserName == username || d.mobphone == username) && d.UserPass == password).ToList();

            if (userList.Count() == 0)
            {
                msg.ErrorMsg = "用户名或密码不正确";
                return;
            }
            else
                userInfo = userList[0];

            if (userInfo == null)
            {
                msg.ErrorMsg = "用户名或密码不正确";
            }
            else
            {
                //if (string.IsNullOrEmpty(userInfo.p))
                //{
                //    userInfo.pccode = System.Guid.NewGuid().ToString();
                //}
                //new QJY_UserB().Update(userInfo);
                msg.Result = userInfo.UserName;
                msg.Result1 = userInfo.ID;
                msg.Result2 = userInfo;
                //LOG异步
                try
                {
                    Task.Factory.StartNew<string>(() =>
                    {
                        new JH_Auth_LogB().Insert(new JH_Auth_Log()
                        {
                            LogType = "PCLOGIN",
                            LogContent = "用户" + userInfo.UserName + "登录，登录时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 登录地点:" + CommonHelp.getIpAddr(),
                            CRUser = userInfo.ID.ToString(),
                            CRDate = DateTime.Now
                        });
                        return "";
                    });


                }
                catch { }
            }
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void REGISTER(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {

            //JObject tt = (JObject)JsonConvert.DeserializeObject(P1);
            //string username = tt["UserRealName"].ToString();
            //if (username == "")
            //{
            //    msg.ErrorMsg = "姓名不能为空!";
            //}
            //string mobile = tt["Phone"].ToString();
            //if (string.IsNullOrEmpty(mobile))
            //{
            //    msg.ErrorMsg = "手机号不能为空!";
            //}
            //if (string.IsNullOrEmpty(tt["Pasword"].ToString()))
            //{
            //    msg.ErrorMsg = "密码不能为空!";
            //}
            //var userlist = new QJY_UserB().GetEntities(p => p.Phone == mobile);
            //if (userlist.Count() > 0)
            //{
            //    msg.ErrorMsg = "此手机已注册用户";
            //}
            //if (msg.ErrorMsg == "")
            //{
            //    QJY_User user = tt.ToObject<QJY_User>();
            //    user.CRDate = DateTime.Now;
            //    user.CRUser = "";
            //    user.UserName = user.Phone;
            //    string password = user.Pasword;
            //    user.Pasword = CommonHelp.GetMD5(password);
            //    new QJY_UserB().Insert(user);
            //    msg.Result = user;
            //    string content = "您的课程管理系统账号已注册成功，信息如下：\r\n登录账号：" + user.UserName + "\r\n密码：" + password + "\r\n,如非本人操作，请忽略本短信";
            //    msg.Result1 = content;
            //}
        }
        /// <summary>
        /// 检查手机号是否注册
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void CHECKREGISTERPHONE(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            var userList = new JH_Auth_UserB().GetEntities(p => p.telphone == P1.Trim());
            if (userList.Count() > 0)
            {
                msg.ErrorMsg = "此手机已注册用户，请更换手机号继续注册";
            }
        }
        /// <summary>
        /// 发送手机验证码
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void SENDCHKMSG(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            if (!string.IsNullOrEmpty(P1))
            {
                string code = CommonHelp.numcode(4);
                try
                {
                    string type = context.Request["type"] ?? "";
                    string content = "";
                    switch (type)
                    {
                        default:
                            content = "教师助手注册验证码为：" + code + "，如非本人操作，请忽略本短信";
                            break;
                    }
                    CommonHelp.SendDX(P1, content, "");
                    msg.Result = CommonHelp.GetMD5(code);
                }
                catch
                {
                    msg.ErrorMsg = "发送验证码失败";
                }
            }
        }
        #endregion

        #region 门户网站

        #region 首页列表
        /// <summary>
        /// 首页列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETINDEXLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            //新闻
            msg.Result = new JH_MH_LMGLB().GetDTByCommand(" select top 8 JH_MH_XWGL.*,JH_MH_LMGL.Name from JH_MH_XWGL  left join JH_MH_LMGL on JH_MH_XWGL.type= JH_MH_LMGL.id order by CRDate desc ");//图片新闻

            //捐赠明细
            msg.Result1 = new xy_jzmxB().GetDTByCommand(" select top 100 * from xy_jzmx where  sfnm=0 order by rq desc ");


            //图片新闻
            //msg.Result2 = new JH_MH_XWGLB().GetEntities(d => d.Files != null && d.Files != "").Take(5);
            //string sql = "select top 5 SUBSTRING(Details, CHARINDEX('<img src=', Details)+10, CHARINDEX('_src', Details)-CHARINDEX('<img src=', Details)-12 ) imgurl,* from JH_MH_XWGL where Details like '%img%' order by CRDate desc";
            //msg.Result2 = XYTXL.API.DbHelperSQL.ExecuteSql(sql);
            msg.Result2 = new JH_MH_XWGLB().GetDTByCommand("select top 5 SUBSTRING(Details, CHARINDEX('<img src=', Details)+10, CHARINDEX('_src', Details)-CHARINDEX('<img src=', Details)-12 ) imgurl,* from JH_MH_XWGL where Details like '%img%' order by CRDate desc");
            //msg.Result2 = new JH_MH_XWGLB().GetDTByCommand(" select top 5 JH_MH_XWGL.*,JH_Auth_FormAttchg.Name from JH_MH_XWGL  left join JH_MH_LMGL on JH_MH_XWGL.type= JH_MH_LMGL.id order by CRDate desc ");//图片新闻


            //校友动态前8条
            msg.Result3 = new JH_MH_XWGLB().GetDTByCommand("select top 8 * from JH_MH_XWGL where TYPE='5' order by CRDate desc");

            //母校要闻前8条
            msg.Result4 = new JH_MH_XWGLB().GetDTByCommand("select top 8 * from JH_MH_XWGL where TYPE='52' order by CRDate desc");

            //人物风采前8条
            msg.Result5 = new JH_MH_XWGLB().GetDTByCommand("select top 8 * from JH_MH_XWGL where TYPE='43' order by CRDate desc");

            //母校要闻前8条
            //msg.r = new JH_MH_XWGLB().GetDTByCommand("select top 8 * from JH_MH_XWGL where TYPE='52' order by CRDate desc");

            ///

        }

        public void GETINDEXLIST1(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            //校友风采图片新闻第一条
            msg.Result = new JH_MH_XWGLB().GetDTByCommand(" select top 1 * from JH_MH_XWGL where Type=43 and isnull(Files,'')!='' order by CRDate desc ");//校友风采
            msg.Result1 = new JH_MH_XWGLB().GetDTByCommand("select top 8 * from JH_MH_XWGL where TYPE='43' order by CRDate desc");

            msg.Result2 = new JH_MH_XWGLB().GetDTByCommand("select top 1 * from JH_MH_XWGL where Type='44' and isnull(Files,'')!='' order by CRDate desc ");//校友企业
            msg.Result3 = new JH_MH_XWGLB().GetDTByCommand("select top 8 * from JH_MH_XWGL where TYPE='44' order by CRDate desc");
            msg.Result4 = new JH_MH_XWGLB().GetDTByCommand("select top 3 SUBSTRING(Details, CHARINDEX('<img src=', Details)+10, CHARINDEX('_src', Details)-CHARINDEX('<img src=', Details)-12 ) imgurl,* from JH_MH_XWGL where  TYPE='53' and Details like '%img%' order by CRDate desc");//老照片
            //msg.Result5= new JH_MH_XWGLB().GetDTByCommand("select top 3 * from JH_MH_XWGL where TYPE='53' order by CRDate desc");

            //捐赠明细


            ///

        }

        #endregion

        #region 栏目列表
        /// <summary>
        /// 栏目列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETLMLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strSQL = "select * from JH_MH_LMGL where TopID=0 and IsDel=0 ";
            if (P1 != "")
            {
                strSQL = strSQL + " AND ID=" + P1;
            }
            strSQL = strSQL + " order by number";
            DataTable dt = new JH_MH_LMGLB().GetDTByCommand(strSQL);

            dt.Columns.Add("Item", Type.GetType("System.Object"));
            foreach (DataRow dr in dt.Rows)
            {
                DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("select * from JH_MH_LMGL where  TopID=" + dr["ID"].ToString() + " and IsDel=0  order by number ");
                dr["Item"] = dtItem;
            }
            msg.Result = dt;
        }

        #endregion

        #region 栏目默认列表
        /// <summary>
        /// 栏目默认列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETLMMRLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            DataTable dtIndex = new JH_MH_LMGLB().GetDTByCommand("select * from JH_MH_LMGL where  TopID=" + P1 + " and IsDel=0  order by number ");
            dtIndex.Columns.Add("List", Type.GetType("System.Object"));
            foreach (DataRow drIndex in dtIndex.Rows)
            {
                DataTable dtIndexList = new JH_MH_XWGLB().GetDTByCommand("select top 5 * from JH_MH_XWGL where  Type=" + drIndex["ID"].ToString() + " order by CRDate desc ");
                drIndex["List"] = dtIndexList;
            }
            msg.Result = dtIndex;
        }

        #endregion

        #region 栏目内容列表
        /// <summary>
        /// 栏目内容列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETNRLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strWhere = " Type=" + P1;
            if (P2 != "")
            {
                strWhere += " and Title like '%" + P2 + "%'";
            }
            int page = 0;
            int pagecount = 8;
            int.TryParse(context.Request.QueryString["p"] ?? "1", out page);
            int.TryParse(context.Request.QueryString["pagecount"] ?? "8", out pagecount);//页数
            page = page == 0 ? 1 : page;
            int total = 0;
            DataTable dt = new DataTable();
            dt = new JH_MH_XWGLB().GetDataPager("JH_MH_XWGL ", "*", pagecount, page, " CRDate desc", strWhere, ref total);

            msg.Result = dt;
            msg.Result1 = total;
        }

        #endregion

        #region 栏目内容
        /// <summary>
        /// 栏目内容
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETNR(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            var nr = new JH_MH_XWGLB().GetEntities(" ID='" + P1 + "' ").FirstOrDefault();
            string strTypeName = new JH_MH_LMGLB().GetEntities(" ID='" + nr.Type + "' ").FirstOrDefault().Name;
            msg.Result = nr;
            msg.Result1 = strTypeName;
            if (!string.IsNullOrEmpty(nr.Files))
            {
                msg.Result2 = new JH_Auth_FormAttchgB().GetDTByCommand("select FileOldName,FileUrl from JH_Auth_FormAttchg where ID in(" + nr.Files + ") ");

            }


        }

        #endregion

        #region 公告内容
        /// <summary>
        /// 公告内容
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETGG(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            var nr = new JH_MH_TZGGB().GetEntities(" ID='" + P1 + "' ").FirstOrDefault();
            msg.Result = nr;
        }

        #endregion

        #endregion




        //校友通讯录
        #region




        /// <summary>
        /// 校友注册
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void XYYZ(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strBH = P1;
            string strName = P2;
            var list = new xy_xsxxB().GetEntities(d => d.bh == P1 && d.xm == P2);
            msg.Result = list;

        }


        public void GETXY(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string PageSize = context.Request.QueryString["pageSize"] ?? "";
            string pageNum = context.Request.QueryString["pageNum"] ?? "";
            string Search = context.Request.QueryString["Search"] ?? "";

            string strWhere = "";
            if (!string.IsNullOrEmpty(Search))
            {
                strWhere = strWhere + " xm+bj like '%" + Search.Trim() + "%'";
            }

            int DataLength = 0;
            DataTable list = new xy_xsxxB().GetDataPager(" xy_xsxx ", "*", int.Parse(PageSize), int.Parse(pageNum), "ID", strWhere, ref DataLength);
            FYClass resu = new FYClass();
            resu.total = DataLength.ToString();
            resu.rows = list;
            msg.Result = resu;
        }


        /// <summary>
        /// 校友注册
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>

        public void XYZC(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strXH = P1;
            string strYHM = P2;
            string psd = context.Request["PSD"] ?? "";
            string dwlb = context.Request["dwlb"] ?? "";
            string dwmc = context.Request["dwmc"] ?? "";
            string gwlbdm = context.Request["gwlb"] ?? "";
            string zwmc = context.Request["zwmc"] ?? "";


            if (dwmc == "")
            {
                msg.ErrorMsg = "单位名称不能为空";
                return;
            }
            if (zwmc == "")
            {
                msg.ErrorMsg = "职位名称不能为空";
                return;
            }

            xy_xsxx MODEL = new xy_xsxxB().GetEntity(d => d.now_smscode == strYHM);
            if (MODEL != null)
            {
                msg.ErrorMsg = "手机号已注册";
            }
            else
            {
                MODEL = new xy_xsxxB().GetEntity(d => d.xh == strXH);
                if (MODEL != null)
                {

                    MODEL.pas = psd;
                    MODEL.sfzc = "1";
                    MODEL.nzcname = strYHM;
                    MODEL.now_smscode = strYHM;
                    MODEL.zcsj = DateTime.Now;
                    MODEL.gwlbdm = gwlbdm;
                    MODEL.zw = zwmc;
                    MODEL.corp_name = dwmc;
                    MODEL.corp_type = dwlb;
                    new xy_xsxxB().Update(MODEL);

                    xy_work WORDMODEL = new xy_work();
                    WORDMODEL.xh = strXH;
                    WORDMODEL.xm = MODEL.xm;

                    WORDMODEL.corp_name = MODEL.corp_name;
                    WORDMODEL.corp_type = MODEL.corp_type;
                    WORDMODEL.gwlbdm = MODEL.gwlbdm;
                    WORDMODEL.zw = MODEL.zw;
                    WORDMODEL.CRDate = DateTime.Now;
                    WORDMODEL.begin_nf = DateTime.Now.ToString("yyyyMM");
                    WORDMODEL.now = "1";
                    new xy_workB().Insert(WORDMODEL);

                }
            }
            msg.Result = MODEL;


        }
        public void GETGWDATA(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            msg.Result = new xy_gwlbB().GetEntities(d => d.ID != 0);//

        }

        public void XYYZSJ(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string txxm = context.Request["txxm"];
            msg.Result = new JWGL_CX().Zcxx(P1, P2, txxm);//

        }

        /// <summary>
        /// 校友登陆
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void XYLOGIN(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string password = context.Request["password"];
            string username = context.Request["UserName"];
            string opendid = context.Request["openid"] ?? "";

            var list = new xy_xsxxB().GetEntities(d => d.nzcname == username && d.pas == password);
            //JH_Auth_User userInfo = new JH_Auth_User();
            List<xy_xsxx> userList = new xy_xsxxB().GetEntities(d => (d.nzcname == username || d.now_smscode == username) && d.pas == password).ToList();
            if (userList.Count() == 0)
            {
                msg.ErrorMsg = "用户名或密码不正确";
                return;
            }
            else
            {
                userList[0].openid = opendid;
                new xy_xsxxB().Update(userList[0]);
                msg.Result = userList[0];
            }


        }
        public void JCBDXX(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {

            string xh = context.Request["xh"] ?? "";

            List<xy_xsxx> userList = new xy_xsxxB().GetEntities(d => d.xh == xh).ToList();
            if (userList.Count() == 0)
            {
                msg.ErrorMsg = "找不到微信信息";
                return;
            }
            else
            {
                userList[0].openid = "";
                new xy_xsxxB().Update(userList[0]);
                msg.Result = userList[0];
            }


        }
        public void GETXSXX(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string xh = context.Request["xh"];
            //JH_Auth_User userInfo = new JH_Auth_User();
            List<xy_xsxx> userList = new xy_xsxxB().GetEntities(d => d.xh == xh).ToList();


            if (userList.Count() == 0)
            {
                msg.ErrorMsg = "找不到信息";
                return;
            }
            else
            {
                userList[0].pas = "";
                msg.Result = userList[0];
            }


        }

        /// <summary>
        /// 获取年级和院系
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETNJANDYX(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            msg.Result = new JH_Auth_FormBaseB().GetDTByCommand(" select distinct nj from xy_bj  order by nj ");//
            msg.Result1 = new JH_Auth_FormBaseB().GetDTByCommand(" select distinct xbmc,xbdm from xy_xbdm  order by xbmc ");//

        }


        /// <summary>
        /// 获取专业
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETZY(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string nj = P1;
            string yx = P2;
            string strSQL = String.Format(" select distinct zymc from xy_bj where 1=1");
            if (!string.IsNullOrEmpty(nj))
            {
                strSQL = strSQL + string.Format(" and nj='{0}'", nj);
            }
            if (!string.IsNullOrEmpty(yx))
            {
                strSQL = strSQL + string.Format(" and xbdm='{0}'", yx);
            }
            strSQL = strSQL + "order by zymc";
            msg.Result = new JH_Auth_FormBaseB().GetDTByCommand(strSQL);//
        }
        public void GETBJ(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string nj = P1;
            string yx = P2;
            string zy = context.Request.QueryString["ZY"] ?? "";

            string strSQL = String.Format(" select distinct bj,bh from xy_bj where 1=1");
            if (!string.IsNullOrEmpty(nj.TrimEnd()))
            {
                strSQL = strSQL + string.Format(" and nj='{0}'", nj.TrimEnd());
            }
            if (!string.IsNullOrEmpty(yx.TrimEnd()))
            {
                strSQL = strSQL + string.Format(" and xbdm='{0}'", yx.TrimEnd());
            }
            if (!string.IsNullOrEmpty(zy.TrimEnd()))
            {
                strSQL = strSQL + string.Format(" and zymc='{0}'", zy.TrimEnd());
            }
            strSQL = strSQL + " order by bj";
            msg.Result = new JH_Auth_FormBaseB().GetDTByCommand(strSQL);//
        }
        public void SAVEDATA(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {

            string strData = context.Request["data"];
            xy_xsxx xs = JsonConvert.DeserializeObject<xy_xsxx>(strData);
            new xy_xsxxB().Update(xs);
            msg.Result = xs;

        }
        public void GETWORKJL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string xh = context.Request["xh"];
            int workid = int.Parse(context.Request["workid"] ?? "0");

            var list = new xy_workB().GetEntities(d => d.xh == xh);
            xy_work work = new xy_work();
            if (workid != 0)
            {
                work = new xy_workB().GetEntities(d => d.ID == workid).FirstOrDefault();
            }
            msg.Result = list;
            msg.Result1 = work;
            msg.Result2 = new xy_gwlbB().GetEntities(d => d.ID != 0);//

        }
        public void SAVEWORKDATA(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {

            string strData = context.Request["data"];
            xy_work work = JsonConvert.DeserializeObject<xy_work>(strData);
            if (work.zc == "")
            {
                msg.ErrorMsg = "职称不能为空";
                return;
            }
            if (work.gwlbdm == "")
            {
                msg.ErrorMsg = "职位类型不能为空";
                return;
            }
            if (work.corp_type == "")
            {
                msg.ErrorMsg = "企业类型不能为空";
                return;
            }
            if (work.corp_name == "")
            {
                msg.ErrorMsg = "企业名称不能为空";
                return;
            }
            int temp = int.Parse(work.gwlbdm);
            xy_gwlb model = new xy_gwlbB().GetEntity(d => d.ID == temp);
            if (model != null)
            {
                work.zw = model.gwlb;
            }
            new xy_workB().Insert(work);
            msg.Result = work;


        }
        public void DELWORKJL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            int workid = int.Parse(context.Request["workid"]);
            new xy_workB().Delete(d => d.ID == workid);//

        }

        public void GETBJXX(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string bj = context.Request["bj"];
            msg.Result = new xy_xsxxB().GetEntities(d => d.bj == bj);

            msg.Result1 = new xy_bjB().GetEntities(d => d.bj == bj).FirstOrDefault();


        }
        public void UPDATEQQ(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string bj = context.Request["bj"];
            string bjqq = context.Request["bjqq"];
            string glyxh = context.Request["glyxh"];
            xy_bj bjmodel = new xy_bjB().GetEntities(d => d.bj == bj).FirstOrDefault();
            bjmodel.bjqq = bjqq;
            bjmodel.glyxh = glyxh;
            new xy_bjB().Update(bjmodel);


        }
        public void GETYCJYXX(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string xh = context.Request["xh"];
            msg.Result = new JWGL_CX().Firstwork(xh);


        }

        public void ADDJH(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {

            xy_jh model = new xy_jh();
            model.jh_addr = context.Request["jhdd"] ?? "";
            model.jh_rq = DateTime.Parse(context.Request["jhsj"] ?? "");
            model.jh_name = context.Request["jhmc"] ?? "";
            model.jh_num = context.Request["jhrs"] ?? "";
            model.jh_tel = context.Request["jhlxdh"] ?? "";
            model.jh_zzr = context.Request["lxr"] ?? "";
            model.jh_nj = context.Request["nj"] ?? "";
            model.jh_zymc = context.Request["zymc"] ?? "";
            model.jh_zydm = context.Request["zydm"] ?? "";
            model.jh_xbmc = context.Request["xbmc"] ?? "";
            model.jh_xbdm = context.Request["xbdm"] ?? "";
            model.jh_bj = context.Request["bj"] ?? "";
            model.jh_bh = context.Request["bh"] ?? "";
            model.bjs = context.Request["bh"] ?? "";
            model.sm = context.Request["jhsm"] ?? "";

            model.shzt = "0";
            model.jh_fqrxh = context.Request["xh"] ?? "";
            model.jh_fqrxm = context.Request["xm"] ?? "";

            model.CRDate = DateTime.Now;
            new xy_jhB().Insert(model);
            msg.Result = model;
        }

        public void MJHLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string xh = context.Request["xh"] ?? "";
            msg.Result = new xy_jhB().GetDTByCommand(" select * from xy_jh where jh_fqrxh='" + xh + "'  order by CRDate desc ");//
            xy_xsxx user = new xy_xsxxB().GetEntities(d => d.xh == xh).FirstOrDefault();
            msg.Result1 = new JH_Auth_FormBaseB().GetDTByCommand(" SELECT * FROM xy_jh WHERE  BJS LIKE '%" + user.bh + "%' ");//
        }



        public void GETWXUSERINFO(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string wxappid = CommonHelp.GetConfig("wxappid");
            string wxsecret = CommonHelp.GetConfig("wxappsecret");
            string code = context.Request["code"] ?? "";
            OAuthAccessTokenResult result = null;

            //通过，用code换取access_token
            try
            {
                result = OAuthApi.GetAccessToken(wxappid, wxsecret, code);
            }
            catch (Exception ex)
            {
                msg.ErrorMsg = ex.Message;
            }
            if (result.errcode != ReturnCode.请求成功)
            {
                msg.ErrorMsg = result.errmsg;
            }
            OAuthUserInfo userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
            msg.Result = userInfo;

            var model = new xy_xsxxB().GetEntities(d => d.openid == userInfo.openid);
            msg.Result1 = model.Count() > 0 ? "Y" : "N";
            if (msg.Result1 == "Y")
            {
                msg.Result2 = model.FirstOrDefault();
            }


        }




        public void GETJZXM(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {

            msg.Result = new xy_jzxmlbB().GetEntities(D => D.ID != 0);
        }

        public void ADDORDER(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            xy_jzmx model = new xy_jzmx();
            model.name = context.Request["xm"] ?? "";
            model.xmdm = context.Request["xmdm"] ?? "";
            model.xmmc = context.Request["xmmc"] ?? "";
            model.lxdh = context.Request["lxdh"] ?? "";
            model.lxr = context.Request["lxr"] ?? "";
            model.je = decimal.Parse(context.Request["je"] ?? "0");
            model.jzlb = "PC";
            model.nj = context.Request["nj"] ?? "";
            model.bj = context.Request["bj"] ?? "";
            model.sfnm = context.Request["sfnm"] ?? "";
            model.sm = context.Request["sm"] ?? "";
            model.rq = DateTime.Now;

            DataTable dtDDH = new xy_jzmxB().GetDTByCommand("select MAX(ddh)+1  AS DDH from xy_jzmx");
            if (dtDDH.Rows.Count > 0)
            {
                model.ddh = int.Parse(dtDDH.Rows[0]["DDH"].ToString());
            }
            else
            {
                model.ddh = 100000;
            }
            msg.Result = model.ddh;
            new xy_jzmxB().Insert(model);
        }

        public void JZMX(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo user)
        {

            DataTable dt = new XYTXL.API.JWGL_CX().Jzxx().Tables[0];
            msg.Result = dt;

        }

        public void JZMXALL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo user)
        {

            DataTable dt = new XYTXL.API.JWGL_CX().Jzxxall().Tables[0];
            msg.Result = dt;

        }



        public void GETNF(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo user)
        {

            DataTable dt = new JH_MH_XWGLB().GetDTByCommand(" SELECT DISTINCT  datename(year,CRDate) AS NF FROM JH_MH_XWGL ORDER BY datename(year,CRDate) DESC ");
            msg.Result = dt;

        }

        public void GETXWLB(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo user)
        {
            string nf = context.Request["nf"] ?? "";
            string type = context.Request["type"] ?? "";
            string strwhere = "";
            if (type != "")
            {
                strwhere = "AND Type=" + type;
            }

            DataTable dt = new JH_MH_XWGLB().GetDTByCommand(" SELECT *  FROM JH_MH_XWGL WHERE 1=1 " + strwhere + "  AND datename(year,CRDate)='" + nf + "' ORDER BY ID DESC  ");
            msg.Result = dt;

        }

        public void GETXWNR(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo user)
        {
            string ID = context.Request["ID"] ?? "";
            DataTable dt = new JH_MH_XWGLB().GetDTByCommand(" SELECT *  FROM JH_MH_XWGL WHERE ID= " + ID);
            msg.Result = dt;

        }


        public void GETJZMX(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo user)
        {
            //捐赠明细
            msg.Result = new xy_jzmxB().GetDTByCommand(" select top 100 * from xy_jzmx where  sfnm=0 order by rq desc ");

        }
        public void DELJH(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo user)
        {
            int ID = int.Parse(context.Request["ID"] ?? "0");
            msg.Result = new xy_jhB().Delete(d => d.ID == ID);

        }


        #endregion





        #region 班级主页查看



        /// <summary>
        /// 获取班级学生信息
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void BJXWLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            msg.Result = new xy_jhB().GetDTByCommand(" select * from jh_BJ_TZGG where TYPE='班级新闻公告' AND  bjdm  ='" + P1.Trim() + "'  ");//
        }



        public void BJZPLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            msg.Result = new xy_jhB().GetDTByCommand(" select * from jh_BJ_TZGG where TYPE='班级照片' AND bjdm  ='" + P1.Trim() + "'  ");//
        }
        public void GETBJNR(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            int id = int.Parse(P1);
            JH_BJ_TZGG MODEL = new jh_BJ_TZGGB().GetEntity(D=>D.ID== id);//
            msg.Result = MODEL;
            if (!string.IsNullOrEmpty(MODEL.Files))
            {
                msg.Result1 = new JH_Auth_FormAttchgB().GetDTByCommand("select FileOldName,FileUrl from JH_Auth_FormAttchg where ID in(" + MODEL.Files + ") ");

            }
        }




        #endregion

        #region 转换图片

        #region 转换图片
        /// <summary>
        /// 首页列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void IMAGECONVERTER(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string path = P1;
            if (File.Exists(path))
            {
                ImageConverterFactory icf = new ImageConverterFactory();

                string fileName = Path.GetFileNameWithoutExtension(path);
                string extendName = Path.GetExtension(path);

                string topath = Path.GetDirectoryName(path) + "/" + fileName + "/";

                if (!Directory.Exists(topath))
                {
                    Directory.CreateDirectory(topath);
                    IImageConverter ic = icf.CreateImageConverter(extendName);
                    ic.ConvertToImage(path, topath);
                }

                //List<string> types = icf.GetSupportedFileTypes();
                //foreach (string type in types)
                //{
                //    string[] fls = Directory.GetFiles(P1, "*" + type, SearchOption.AllDirectories); ;

                //    foreach (string name in fls)
                //    {
                //        string fileName = Path.GetFileNameWithoutExtension(name);
                //        string extendName = Path.GetExtension(name);
                //        string path = Path.GetDirectoryName(name);

                //        if (icf.Support(extendName))
                //        {
                //            string wjj = fileName + extendName.Replace('.', '_');
                //            if (!Directory.Exists(path + "/" + wjj + "/"))
                //            {
                //                Directory.CreateDirectory(path + "/" + wjj + "/");
                //                IImageConverter ic = icf.CreateImageConverter(extendName);
                //                ic.ConvertToImage(name, path + "/" + wjj + "/");
                //            }
                //        }
                //    }
                //}
            }
        }

        #endregion

        #region 图片转换器工厂
        /// <summary>
        /// 图片转换器工厂。
        /// </summary>
        public class ImageConverterFactory : IImageConverterFactory
        {
            public IImageConverter CreateImageConverter(string extendName)
            {
                if (extendName == ".doc" || extendName == ".docx")
                {
                    return new Word2ImageConverter();
                }

                if (extendName == ".pdf")
                {
                    return new Pdf2ImageConverter();
                }

                if (extendName == ".ppt" || extendName == ".pptx")
                {
                    return new Ppt2ImageConverter();
                }

                return null;
            }

            public bool Support(string extendName)
            {
                //return extendName == ".doc" || extendName == ".docx" || extendName == ".pdf" || extendName == ".ppt" || extendName == ".pptx" ;
                return extendName == ".doc" || extendName == ".docx" || extendName == ".pdf" || extendName == ".pptx";
            }

            public List<string> GetSupportedFileTypes()
            {
                List<string> list = new List<string>();
                list.Add(".doc");
                list.Add(".docx");
                list.Add(".pdf");
                //list.Add(".ppt");
                list.Add(".pptx");
                return list;
            }
        }
        #endregion

        #region 将word文档转换为图片
        public class Word2ImageConverter : IImageConverter
        {
            private bool cancelled = false;
            public event CbGeneric<int, int> ProgressChanged;
            public event CbGeneric ConvertSucceed;
            public event CbGeneric<string> ConvertFailed;

            public void Cancel()
            {
                if (this.cancelled)
                {
                    return;
                }

                this.cancelled = true;
            }

            public void ConvertToImage(string originFilePath, string imageOutputDirPath)
            {
                this.cancelled = false;
                ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, null, 200);
            }

            /// <summary>
            /// 将Word文档转换为图片的方法      
            /// </summary>
            /// <param name="wordInputPath">Word文件路径</param>
            /// <param name="imageOutputDirPath">图片输出路径，如果为空，默认值为Word所在路径</param>      
            /// <param name="startPageNum">从PDF文档的第几页开始转换，如果为0，默认值为1</param>
            /// <param name="endPageNum">从PDF文档的第几页开始停止转换，如果为0，默认值为Word总页数</param>
            /// <param name="imageFormat">设置所需图片格式，如果为null，默认格式为PNG</param>
            /// <param name="resolution">设置图片的像素，数字越大越清晰，如果为0，默认值为128，建议最大值不要超过1024</param>
            private void ConvertToImage(string wordInputPath, string imageOutputDirPath, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution)
            {
                try
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);

                    if (doc == null)
                    {
                        throw new Exception("Word文件无效或者Word文件被加密！");
                    }

                    if (imageOutputDirPath.Trim().Length == 0)
                    {
                        imageOutputDirPath = Path.GetDirectoryName(wordInputPath);
                    }

                    if (!Directory.Exists(imageOutputDirPath))
                    {
                        Directory.CreateDirectory(imageOutputDirPath);
                    }

                    if (startPageNum <= 0)
                    {
                        startPageNum = 1;
                    }

                    if (endPageNum > doc.PageCount || endPageNum <= 0)
                    {
                        endPageNum = doc.PageCount;
                    }

                    if (startPageNum > endPageNum)
                    {
                        int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
                    }

                    if (imageFormat == null)
                    {
                        imageFormat = ImageFormat.Png;
                    }

                    if (resolution <= 0)
                    {
                        resolution = 128;
                    }

                    string imageName = Path.GetFileNameWithoutExtension(wordInputPath);
                    Aspose.Words.Saving.ImageSaveOptions imageSaveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png);
                    imageSaveOptions.Resolution = resolution;
                    for (int i = startPageNum; i <= endPageNum; i++)
                    {
                        if (this.cancelled)
                        {
                            break;
                        }

                        MemoryStream stream = new MemoryStream();
                        imageSaveOptions.PageIndex = i - 1;
                        string imgPath = Path.Combine(imageOutputDirPath, imageName) + "_" + i.ToString("000") + "." + imageFormat.ToString();
                        doc.Save(stream, imageSaveOptions);
                        Image img = Image.FromStream(stream);
                        Bitmap bm = ESBasic.Helpers.ImageHelper.Zoom(img, 0.6f);
                        bm.Save(imgPath, imageFormat);
                        img.Dispose();
                        stream.Dispose();
                        bm.Dispose();

                        System.Threading.Thread.Sleep(200);
                        if (this.ProgressChanged != null)
                        {
                            this.ProgressChanged(i - 1, endPageNum);
                        }
                    }

                    if (this.cancelled)
                    {
                        return;
                    }

                    if (this.ConvertSucceed != null)
                    {
                        this.ConvertSucceed();
                    }
                }
                catch (Exception ex)
                {
                    if (this.ConvertFailed != null)
                    {
                        this.ConvertFailed(ex.Message);
                    }
                }
            }
        }
        #endregion

        #region 将pdf文档转换为图片
        public class Pdf2ImageConverter : IImageConverter
        {
            private bool cancelled = false;
            public event CbGeneric<int, int> ProgressChanged;
            public event CbGeneric ConvertSucceed;
            public event CbGeneric<string> ConvertFailed;

            public void Cancel()
            {
                if (this.cancelled)
                {
                    return;
                }

                this.cancelled = true;
            }

            public void ConvertToImage(string originFilePath, string imageOutputDirPath)
            {
                this.cancelled = false;
                ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, 200);
            }

            /// <summary>
            /// 将pdf文档转换为图片的方法      
            /// </summary>
            /// <param name="originFilePath">pdf文件路径</param>
            /// <param name="imageOutputDirPath">图片输出路径，如果为空，默认值为pdf所在路径</param>       
            /// <param name="startPageNum">从PDF文档的第几页开始转换，如果为0，默认值为1</param>
            /// <param name="endPageNum">从PDF文档的第几页开始停止转换，如果为0，默认值为pdf总页数</param>       
            /// <param name="resolution">设置图片的像素，数字越大越清晰，如果为0，默认值为128，建议最大值不要超过1024</param>
            private void ConvertToImage(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution)
            {
                try
                {
                    Aspose.Pdf.Document doc = new Aspose.Pdf.Document(originFilePath);

                    if (doc == null)
                    {
                        throw new Exception("pdf文件无效或者pdf文件被加密！");
                    }

                    if (imageOutputDirPath.Trim().Length == 0)
                    {
                        imageOutputDirPath = Path.GetDirectoryName(originFilePath);
                    }

                    if (!Directory.Exists(imageOutputDirPath))
                    {
                        Directory.CreateDirectory(imageOutputDirPath);
                    }

                    if (startPageNum <= 0)
                    {
                        startPageNum = 1;
                    }

                    if (endPageNum > doc.Pages.Count || endPageNum <= 0)
                    {
                        endPageNum = doc.Pages.Count;
                    }

                    if (startPageNum > endPageNum)
                    {
                        int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
                    }

                    if (resolution <= 0)
                    {
                        resolution = 128;
                    }

                    string imageNamePrefix = Path.GetFileNameWithoutExtension(originFilePath);
                    for (int i = startPageNum; i <= endPageNum; i++)
                    {
                        if (this.cancelled)
                        {
                            break;
                        }

                        MemoryStream stream = new MemoryStream();
                        string imgPath = Path.Combine(imageOutputDirPath, imageNamePrefix) + "_" + i.ToString("000") + ".jpg";
                        Aspose.Pdf.Devices.Resolution reso = new Aspose.Pdf.Devices.Resolution(resolution);
                        Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice(reso, 100);
                        jpegDevice.Process(doc.Pages[i], stream);

                        Image img = Image.FromStream(stream);
                        Bitmap bm = ESBasic.Helpers.ImageHelper.Zoom(img, 0.6f);
                        bm.Save(imgPath, ImageFormat.Jpeg);
                        img.Dispose();
                        stream.Dispose();
                        bm.Dispose();

                        System.Threading.Thread.Sleep(200);
                        if (this.ProgressChanged != null)
                        {
                            this.ProgressChanged(i - 1, endPageNum);
                        }
                    }

                    if (this.cancelled)
                    {
                        return;
                    }

                    if (this.ConvertSucceed != null)
                    {
                        this.ConvertSucceed();
                    }
                }
                catch (Exception ex)
                {
                    if (this.ConvertFailed != null)
                    {
                        this.ConvertFailed(ex.Message);
                    }
                }
            }
        }
        #endregion

        #region 将ppt文档转换为图片
        public class Ppt2ImageConverter : IImageConverter
        {
            private Pdf2ImageConverter pdf2ImageConverter;
            public event CbGeneric<int, int> ProgressChanged;
            public event CbGeneric ConvertSucceed;
            public event CbGeneric<string> ConvertFailed;

            public void Cancel()
            {
                if (this.pdf2ImageConverter != null)
                {
                    this.pdf2ImageConverter.Cancel();
                }
            }

            public void ConvertToImage(string originFilePath, string imageOutputDirPath)
            {
                ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, 200);
            }

            /// <summary>
            /// 将pdf文档转换为图片的方法      
            /// </summary>
            /// <param name="originFilePath">ppt文件路径</param>
            /// <param name="imageOutputDirPath">图片输出路径，如果为空，默认值为pdf所在路径</param>       
            /// <param name="startPageNum">从PDF文档的第几页开始转换，如果为0，默认值为1</param>
            /// <param name="endPageNum">从PDF文档的第几页开始停止转换，如果为0，默认值为pdf总页数</param>       
            /// <param name="resolution">设置图片的像素，数字越大越清晰，如果为0，默认值为128，建议最大值不要超过1024</param>
            private void ConvertToImage(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution)
            {
                try
                {
                    Aspose.Slides.Presentation doc = new Aspose.Slides.Presentation(originFilePath);

                    if (doc == null)
                    {
                        throw new Exception("ppt文件无效或者ppt文件被加密！");
                    }

                    if (imageOutputDirPath.Trim().Length == 0)
                    {
                        imageOutputDirPath = Path.GetDirectoryName(originFilePath);
                    }

                    if (!Directory.Exists(imageOutputDirPath))
                    {
                        Directory.CreateDirectory(imageOutputDirPath);
                    }

                    if (startPageNum <= 0)
                    {
                        startPageNum = 1;
                    }

                    if (endPageNum > doc.Slides.Count || endPageNum <= 0)
                    {
                        endPageNum = doc.Slides.Count;
                    }

                    if (startPageNum > endPageNum)
                    {
                        int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
                    }

                    if (resolution <= 0)
                    {
                        resolution = 128;
                    }

                    //先将ppt转换为pdf临时文件
                    string tmpPdfPath = originFilePath + ".pdf";
                    doc.Save(tmpPdfPath, Aspose.Slides.Export.SaveFormat.Pdf);

                    //再将pdf转换为图片
                    Pdf2ImageConverter converter = new Pdf2ImageConverter();
                    converter.ConvertFailed += new CbGeneric<string>(converter_ConvertFailed);
                    converter.ConvertSucceed += new CbGeneric(converter_ConvertSucceed);
                    converter.ProgressChanged += new CbGeneric<int, int>(converter_ProgressChanged);
                    converter.ConvertToImage(tmpPdfPath, imageOutputDirPath);

                    //删除pdf临时文件
                    File.Delete(tmpPdfPath);

                    if (this.ConvertSucceed != null)
                    {
                        this.ConvertSucceed();
                    }
                }
                catch (Exception ex)
                {
                    if (this.ConvertFailed != null)
                    {
                        this.ConvertFailed(ex.Message);
                    }
                }

                this.pdf2ImageConverter = null;
            }

            void converter_ProgressChanged(int done, int total)
            {
                if (this.ProgressChanged != null)
                {
                    this.ProgressChanged(done, total);
                }
            }

            void converter_ConvertSucceed()
            {
                if (this.ConvertSucceed != null)
                {
                    this.ConvertSucceed();
                }
            }

            void converter_ConvertFailed(string msg)
            {
                if (this.ConvertFailed != null)
                {
                    this.ConvertFailed(msg);
                }
            }
        }
        #endregion

        #endregion
    }
}